package com.itheima.bos.service.impl;

import com.itheima.bos.dao.IStaffDao;
import com.itheima.bos.domain.Staff;
import com.itheima.bos.service.IStaffService;
import com.itheima.bos.utils.PageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by Mr.King on 2017/3/9.
 */
@Service
@Transactional
public class StaffServiceImpl implements IStaffService {

    @Autowired
    private IStaffDao iStaffDao;

    @Override
    public void staffAdd(Staff model) {
        iStaffDao.save(model);
    }

    @Override
    public void pageQuery(PageBean pageBean) {
        iStaffDao.pageQuery(pageBean);
    }

    @Override
    public void delete(String ids) {
        String[] split = ids.split(",");
        for (int i=0;i < split.length ; i++){
            Staff staff = iStaffDao.findById(split[i]);
            staff.setDeltag("1");
        }
    }

    @Override
    public void restore(String ids) {
        String[] split = ids.split(",");
        for (int i=0;i < split.length; i++){
            Staff staff = iStaffDao.findById(split[i]);
            staff.setDeltag("0");
        }

    }

    @Override
    public void update(Staff model) {
        iStaffDao.update(model);
    }

    @Override
    public List<Staff> findAll() {
        return iStaffDao.findAll();
    }
}
